#include <iostream>
#include <cstring>
using namespace std;

 #define PRINT_ARRAY(array,n) \
    for (int idx = 0 ;idx <(n) ; idx++) \
        cout << "array[" << idx <<"] = " <<(array)[idx]<<endl; 

int main()
{
    // this is a simple example of Pointer 
    /*
    int num =10;
    int *p1 = NULL, *p2 = NULL;
    p1 = &num;
    p2 = &num;
    cout << num << endl; 
    *p1 = 20;
    cout << num << " " << *p1 << endl; 
    *p2 = 30;
    cout << num << "Pointer :p2 " << *p2 << endl; 

    cout << num << "Pointer :p1" << *p1 << endl;
       
    return 0;
    */
 
   // this is an example of useing a Pointer to control a struct
    // struct Student 
    // {
    //     char name[4];
    //     int born;
    //     bool male;
    // };
    // Student stu = {"Yu",2000,true};
    // Student *Pstu = &stu;
    
    // strncpy(Pstu->name, "li",4);
    // Pstu->born =2001;
    // (*Pstu).born =2002;
    // Pstu->male =false;
    // cout << stu.name << " " << stu.born << " " << stu.male << endl;


    // here is the Pointer shift operation.
    // int number[4] = {0,1,2,3};
    // int *p = number+1; // here is Pointer  operation added by one.
    // PRINT_ARRAY(number, 4);
    // p++; // add one to the position of the pointer.
    // cout << "number = " << number << endl;
    // cout << "p = "<< p << endl;
    
    // *p = 20;    //  Because the position above is added by one ,so the position is now the third position of the array.
    // *(p-1) = 10;   // here is Pointer operation -1.
    // p[1] = 30; // here is Pointer operation +1.
    // PRINT_ARRAY(number, 4);

    // int a;
    // int num =0;
    // int *p = &num;
    // p[-1] = 2; // The pointer out of bounds here is an error, Minimize occurrence
    // p[0] = 3;
    // *(p+1) = 4;
    // cout << "num = " << num << endl;

     
    //Constant pointers usage .
    //
    // int num = 1;
    // int another =2;
    // const int *p1 = &num;
    // *p1 = 3;   The error here is due to the pointer constant specified above.
    // so you can't change.
    // num = 3; //But you can modify the value by assigning a variable.
    // you cannot modify the value above through the pointer.
    // int num = 1 ;
    // int another = 2;
    // int * const p2 = &num;
    // *p2 = 3 ;
    // p2 = &another;baceuse p2(address) has been defined above ,you cannot change it.
    // 
    // The following example , you cannot change either of them;
    //
    // const int* const p3 =&num;




    return 0;
}